package ui.robots_wicket;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;

import ui.robots_wicket.applicationsModels.HomePageModel;

public class HomePage extends WebPage {
	private static final long serialVersionUID = 1L;
	private HomePageModel homePageModel;

	public HomePage() {
		Form<HomePageModel> form = new Form<HomePageModel>("ingresarForm", this.createModel());
		this.add(form);
		this.addFields(form);
		this.addActions(form);
	}

	protected CompoundPropertyModel<HomePageModel> createModel() {
		this.homePageModel = new HomePageModel();
		return new CompoundPropertyModel<HomePageModel>(this.homePageModel);
	}

	private void addActions(final Form<HomePageModel> form) {
		form.add(new Button("ingresar") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit() {
				this.setResponsePage(new MainPage(form.getModelObject().agregarJugador()));
			}
		});
	}

	private void addFields(Form<HomePageModel> form) {
		form.add(new TextField<String>("nombre"));
	}
}
